package com.yonyou.pmclouds.billtype.rmiimpl;

import com.alibaba.dubbo.config.annotation.Service;
import com.yonyou.pmclouds.ApplicationConsts;
import com.yonyou.pmclouds.basecom.bp.processor.AuditInfoInsertProcessor;
import com.yonyou.pmclouds.basecom.bp.processor.AuditInfoUpdateProcessor;
import com.yonyou.pmclouds.basecom.bp.template.SingleDeleteBpTemplate;
import com.yonyou.pmclouds.basecom.bp.template.SingleInsertBpTemplate;
import com.yonyou.pmclouds.basecom.bp.template.SingleUpdateBpTemplate;
import com.yonyou.pmclouds.basecom.exception.BusinessException;
import com.yonyou.pmclouds.basecom.util.CommonFieldConst;
import com.yonyou.pmclouds.billtype.entity.BillTypeVO;
import com.yonyou.pmclouds.billtype.mapper.BillTypeVOMapper;
import com.yonyou.pmclouds.billtype.rmiitf.BillTypeMaintain;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * 单据类型
 *
 * @author yzx
 */
@Service(version = ApplicationConsts.APPLICATION_VERSION, interfaceClass = BillTypeMaintain.class)
public class BillTypeMaintainImpl implements BillTypeMaintain {
    private static final String[] UPDATE_FIELDS = new String[]{CommonFieldConst.SNAME};

    @Autowired
    private BillTypeVOMapper mapper;
    @Override
    public BillTypeVO insert(BillTypeVO billTypeVO) throws BusinessException {
        SingleInsertBpTemplate<BillTypeVO> bp = new SingleInsertBpTemplate<BillTypeVO>(mapper);
        // 更新审计信息
        bp.addBeforeProcessor(new AuditInfoInsertProcessor<BillTypeVO>());
        bp.insert(billTypeVO);
        return billTypeVO;
    }

    @Override
    public void delete(BillTypeVO billTypeVO) throws BusinessException {
        SingleDeleteBpTemplate<BillTypeVO> deleteBpTemplate = new SingleDeleteBpTemplate<>(mapper);
        deleteBpTemplate.delete(billTypeVO);
    }

    @Override
    public BillTypeVO update(BillTypeVO billTypeVO) throws BusinessException {
        SingleUpdateBpTemplate<BillTypeVO> bp = new SingleUpdateBpTemplate<>(mapper, UPDATE_FIELDS);
        //审计信息
        bp.addBeforeProcessor(new AuditInfoUpdateProcessor<BillTypeVO>());
        bp.update(billTypeVO);
        return billTypeVO;
    }

}

